// /** @param {NS} ns */
// export async function main(ns) {

// }

/**
 * Find all adjacent points in the four connected directions
 */
export const get_neighbors_4 = (board, x, y,ns) => {
  const north = board[x + 1]?.[y];
  const east = board[x][y + 1];
  const south = board[x - 1]?.[y];
  const west = board[x]?.[y - 1];

  return [north, east, south, west];
};

function isAvalablePos(posX,posY,totalLength)
{
  if(totalLength<=posX || posX<0)
  {
    return false;
  }
  if(totalLength<=posY || posY<0)
  {
    return false;
  }
  return true;
}

export const get_neighbors_8 = (board, x, y,ns) => {
  const north = board[x + 1]?.[y];
  const east = board[x][y + 1];
  const south = board[x - 1]?.[y];
  const west = board[x]?.[y - 1];

  var result = [north, east, south, west]


  const length =board.length; 
  if(length>(x + 1) && 0<=y-1)
  {
    result.push(board[x + 1][y-1]);
  }
  if(isAvalablePos(x+1,y+1,length))
  {
    result.push(board[x + 1][y+1]);
  }
  if(isAvalablePos(x-1,y+1,length))
  {
    result.push(board[x - 1][y+1]);
  }
  if(isAvalablePos(x-1,y-1,length))
  {
    result.push(board[x - 1][y-1]);
  }
  
  return result;
};